package com.ease.component.controls.transitionclass {
import mx.core.UIComponent;
import mx.states.IOverride;

public class HideChildren implements IOverride {
   //---------------------------------------------------------------------------
   // Constructor

   /**
    * Creates a hide children view state override.
    */
   public function HideChildren(target:UIComponent = null) {
      super();

      this.target = target;
   }

   //---------------------------------------------------------------------------
   // Instance Variables

   /** Property to check whether the children have been hidden. */
   private var _childrenHidden:Boolean;

   [Inspectable (category = "General")]

   /** Reference to the container whose children should be hidden. */
   public var target:UIComponent;

   public function initialize():void {
   }

   /**
    * @inheritDoc
    */
   public function apply(parent:UIComponent):void {
      _childrenHidden = false;

      if (target == null) {
         return;
      }
      for (var i:int = 0; i < target.numChildren; i++) {
         var child:UIComponent = target.getChildAt(i) as UIComponent;
         child.visible = false;
         child.includeInLayout = false;
      }
      _childrenHidden = true;
   }

   /**
    * @inheritDoc
    */
   public function remove(parent:UIComponent):void {
      if (target == null) {
         return;
      }
      for (var i:int = 0; i < target.numChildren; i++) {
         var child:UIComponent = target.getChildAt(i) as UIComponent;
         child.visible = true;
         child.includeInLayout = true;
      }

      _childrenHidden = false;
   }
}
}